using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using CodePlex.TfsLibrary.Utility;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("diagnostics", "Displays diagnostic information.", AltName = "diag", MaxArgs = 0,
        UsageDescription = @"This information may be requested by CodePlex team members to help diagnose
bugs in this software.")]
    public class DiagnosticsCommand : Command
    {
        public override void Execute()
        {
            string executableName = new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath;
            List<string> files = new List<string>(Directory.GetFiles(Path.GetDirectoryName(executableName), "CodePlex.*.dll"));
            files.Sort();
            files.Insert(0, executableName);

            Console.WriteLine("File versions:");

            foreach (string pathName in files)
            {
                string fileName = Path.GetFileName(pathName);
                Assembly assm = Assembly.ReflectionOnlyLoadFrom(pathName);
                Console.WriteLine("  {0} ({1})", fileName, ReflectionUtil.GetAssemblyVersion(assm));
            }
        }
    }
}